package com.luke.star.helper.serviceImpl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.luke.star.bean.StException;
import com.luke.star.enums.ErrorCodeEnum;
import com.luke.star.persist.mapper.StAssignmentLogMapper;
import com.luke.star.persist.mapper.StAssignmentMapper;
import com.luke.star.persist.mapper.StTaskMapper;
import com.luke.star.persist.mapper.StTaskNoteMapper;
import com.luke.star.persist.po.StAssignment;
import com.luke.star.persist.po.StAssignmentLog;
import com.luke.star.persist.po.StTask;
import com.luke.star.persist.po.StTaskNote;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class StAssignmentHelperService {
	@Resource
	private StTaskMapper stTaskMapper;
	@Resource
	private StTaskNoteMapper stTaskNoteMapper;
	@Resource
	private StAssignmentMapper stAssignmentMapper;
	@Resource
	private StAssignmentLogMapper stAssignmentLogMapper;
	
	
	public void updateAssiJobData(StTask task,StTaskNote tasknote,StAssignment assi,StAssignmentLog assiLog) {
		try {
			int count1 = stTaskMapper.updateByPrimaryKeySelective(task);
			if(count1 != 1) {
				log.error("任务数据更新失败，taskid[{}]",task.getId());
				throw new StException(ErrorCodeEnum.s0003.code,ErrorCodeEnum.s0003.desc);
			}
			
			int count2 = stTaskNoteMapper.insertSelective(tasknote);
			if(count2 != 1) {
				log.error("任务日志插入失败，taskid[{}]",tasknote.getTaskId());
				throw new StException(ErrorCodeEnum.s0004.code,ErrorCodeEnum.s0004.desc);
			}
			
			int count3 = stAssignmentMapper.updateByPrimaryKeySelective(assi);
			if(count3 != 1) {
				log.error("分解任务数据更新失败，assiId[{}]",assi.getAssiId());
				throw new StException(ErrorCodeEnum.s0003.code,ErrorCodeEnum.s0003.desc);
			}
			
			int count4 = stAssignmentLogMapper.insertSelective(assiLog);
			if(count4 != 1) {
				log.error("分解任务日志插入失败，assiId[{}]",assiLog.getAssiId());
				throw new StException(ErrorCodeEnum.s0004.code,ErrorCodeEnum.s0004.desc);
			}
		}catch (StException e) {
			throw e;
		}catch (Exception e) {
			log.error("分解任务批量数据更新失败，已修改的数据会还原，assiId[{}],",assi.getAssiId(),e);
			throw new StException(ErrorCodeEnum.s0003.code,ErrorCodeEnum.s0003.desc);
		}
	}
	
	
	
	
}
